package cn.yang.domain.strategy.model.entity;

import cn.yang.types.common.Constants;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Date;

/**
 * @version v1.0
 * @ClassName: cn.yang.domain.strategy.model.entity
 * @Description: 策略实体
 * @Author: YJ
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class StrategyEntity {

    /**
     * 抽奖策略id
     */
    private Long strategyId;
    /**
     * 抽奖策略描述
     */
    private String strategyDesc;

    /**
     * 抽奖规则
     */
    private String ruleModels;

    public String[] ruleModels() {
        if (StringUtils.isBlank(ruleModels)) return null;
        return ruleModels.split(Constants.SPLIT);
    }

    public String getRuleWeight() {
        String[] ruleModels = this.ruleModels();
        // 如果没有规则模型，直接返回null
        if(ruleModels == null) return null;
        for (String ruleModel : ruleModels) {
            if ("rule_weight".equals(ruleModel)) return ruleModel;
        }
        return null;
    }

}
